I'm trying to convert 2022-01-17T21:36:04.000Z into January 18th type format. I'm doing with the help of npm package dateFormat.
I'm able to achieve this easily with:
const date = dateFormat("2022-01-17T21:36:04.000Z", "mmmm dS");
But instead of hardcoding if I pass value like this, it doesn't seem to work.
const convertDate = (dateformat) => {
const date = dateFormat(`"${dateformat}"`, "mmmm dS");
console.log(date);
I'm getting TypeError: Invalid date.
console.log(`"${dateformat}"`) // is giving me -> "2022-01-17T21:36:04.000Z"
Instead of
const date = dateFormat(`"${dateformat}"`, "mmmm dS");
use the variable directly:
const date = dateFormat(dateformat, "mmmm dS");